package com.ljy.my_study.java;

/**
 * @author lijunying
 * @date 2021/2/22 8:38
 */
public class FundTestMain {

    public static void main(String[] args) {
//        每年收入
        int all=120_000;
//        每年投入基金数额
        int money=12_000;
//        投资十年
        int year=20;
//        年收益率
        double rate=0.1;
        System.out.println(calculate2(all-money,year));
        System.out.println(calculate(money,rate,year));
        System.out.println(all-money);
        System.out.println(calculate(money,rate,year)-calculate2(money,year));
        System.out.println(calculate2(all-money,year)+calculate(money,rate,year));
    }

    public static double calculate2(double money,int year){
        return money*year;
    }

    public static double calculate(double money,double rate,int year){
        if(year==1){
            return money*(1+rate);
        }
        return (calculate(money,rate,year-1)+money)*(1+rate);
    }

}
